#include "sciter-x.h"
#include "sciter-x-behavior.h"
#include "sciter-x-graphics.hpp"

#include "lvgl_init.h"

namespace sciter
{

struct watch_drawing: public event_handler
{
    // ctor
    watch_drawing() {}
    virtual ~watch_drawing() {}

    virtual bool subscription( HELEMENT he, UINT& event_groups )
    {
      event_groups = HANDLE_DRAW;  // it does drawing
      return true;
    }

    virtual void attached  (HELEMENT he ) { }
    virtual void detached  (HELEMENT he ) { asset_release(); }
    
    virtual bool handle_draw(HELEMENT he, DRAW_PARAMS& params ) 
    {
        if( params.cmd != DRAW_CONTENT ) return false; // drawing only content layer

        unsigned w = unsigned(params.area.right - params.area.left);
        unsigned h = unsigned(params.area.bottom - params.area.top);

         if (monitor.refr_qry) {
			 sciter::image img = sciter::image::create(DISP_HOR_RES, DISP_VER_RES, false, (const unsigned char*)monitor.tft_fb);

			 sciter::graphics gfx(params.gfx);
			 gfx.draw_image(&img, POS(params.area.left), POS(params.area.top));
             monitor.refr_qry = false;
        }

        return true;
    
    }
};

struct watch_drawing_factory: public behavior_factory {

    watch_drawing_factory(): behavior_factory("watch-drawing") { }

  // the only behavior_factory method:
  virtual event_handler* create(HELEMENT he) {
    return new watch_drawing();
  }

};

// instantiating and attaching it to the global list
watch_drawing_factory gdi_drawing_factory_instance;


}
